#include "junix.h"
using namespace std;


//STL traits
//diff from Boost

struct true_value { };
struct false_value { };

template <typename Type>
struct traits {
	typedef false_value is_POD;
};

template<>
struct traits<char> {
	typedef true_value is_POD;
};



template<typename Iterator>
void __jcopy(Iterator* __a,
	     	Iterator* __b, 
			Iterator* __c,
			true_value _tv) {
	std::cout<<"POD copy\n";
	memmove((char*)__c,(char*)__a, (ptrdiff_t)(__b-__a));
}

template<typename Iterator>
void __jcopy(Iterator* __a,
	     	Iterator* __b, 
			Iterator* __c,
			false_value _tv) {
	std::cout<<"non-POD copy\n";
	while (__a!=__b) {
		*__c++ = *__a++;
	}
}

template<typename Iterator>
void jcopy(Iterator* __a, Iterator* __b, Iterator* __c) {
	typename traits<Iterator>::is_POD __is_pod;
	__jcopy(__a, __b, __c, __is_pod);
}


int main(int argc, char **argv)
{
	char p[] = "hello,world!\n";
	char b[20]={'\0'};


	jcopy(p,p+strlen(p),b);
	cout<<b;

	int iv1[] = {1,2,3,4,5,6,7,8};
	int iv2[8];
	jcopy(iv1,iv1+8,iv2);
	copy(iv1,iv1+8,ostream_iterator<int>(cout," "));
	cout<<endl;
}
